package boot.spring.service.impl;

import java.util.Map;

import org.activiti.engine.IdentityService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.runtime.ProcessInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import boot.spring.mapper.SetSecretMapper;
import boot.spring.po.SetSecretApply;
import boot.spring.service.SetSecretService;


@Transactional(propagation=Propagation.REQUIRED,isolation=Isolation.DEFAULT,timeout=5)
@Service
public class SetSecretServiceImpl implements SetSecretService{
	
	@Autowired
	SetSecretMapper setSecretMapper;
	@Autowired
	IdentityService identityservice;
	@Autowired
	RuntimeService runtimeservice;

	@Override
	public ProcessInstance startWorkflow(SetSecretApply apply, String userid, Map<String, Object> variables) {
		setSecretMapper.save(apply);
		String businesskey=String.valueOf(apply.getId());//使用leaveapply表的主键作为businesskey,连接业务数据和流程数据
		identityservice.setAuthenticatedUserId(userid);
		ProcessInstance instance=runtimeservice.startProcessInstanceByKey("givenSecret",businesskey,variables);
//		String instanceid=instance.getId();
		return instance;
	}

	@Override
	public SetSecretApply getSetSecretApply(int id) {
		return setSecretMapper.getSetSecretApply(id);
	}

}
